package com.zx.mobile.service.proxy;

import com.zx.map.service.model.BaseAcctInfoModel;
import com.zx.map.service.model.CustAcctLogModel;
import com.zx.map.service.model.ShareProfitLogModel;
import org.apache.log4j.Logger;

import java.math.BigDecimal;
import java.util.Date;

public class ShareProfitServiceProxy {
	/**
	 * log
	 */
	private static Logger log = Logger.getLogger(ShareProfitServiceProxy.class);

	/**
	 * 模型转换
	 * 
	 * @param temp
	 * @param transAmt
	 * @return
	 */
	public static BaseAcctInfoModel transformBaseAcct(BaseAcctInfoModel temp,
			String transAmt) {
		BigDecimal avlAmt = new BigDecimal(temp.getAvlBal().toString());
		BigDecimal acctAmt = new BigDecimal(temp.getAcctBal().toString());
		temp.setAvlBal(avlAmt.add(new BigDecimal(transAmt)).doubleValue());
		temp.setAcctBal(acctAmt.add(new BigDecimal(transAmt)).doubleValue());
		return temp;
	}

	/**
	 * 模型转换 转换成账务流水
	 * @param baseModel 	 *
	 * @param spTemp
	 * @param tradeAmt
	 * @return
	 */
	public static CustAcctLogModel transformCustAcct(
			BaseAcctInfoModel baseModel, ShareProfitLogModel spTemp, String tradeAmt) {
		CustAcctLogModel temp = new CustAcctLogModel();
		temp.setAcctBal(baseModel.getAvlBal());
		temp.setAcctType("B");
		temp.setCreateDate(new Date());
		temp.setCustId(spTemp.getCustId());
		temp.setCustSysaccount(spTemp.getCustSysAccount());
		temp.setOrdId(spTemp.getSprofitId());
		temp.setRemark("");
		temp.setOriginalAmt(Double.parseDouble(tradeAmt));//增加账户变化原始交易金额
		temp.setTransAmt(Double.parseDouble(tradeAmt));
		temp.setTransType("3001");// 分享收益转出
		return temp;
	}

	/**
	 * 扣减金额
	 * @param spTemp
	 * @param tradeAmt
	 * @return
	 */
	public static ShareProfitLogModel transformSpModel(
			ShareProfitLogModel spTemp, String tradeAmt) {
		BigDecimal sp = new BigDecimal(spTemp.getSprofitAvlAmt().toString());
		spTemp.setSprofitAvlAmt(sp.subtract(new BigDecimal(tradeAmt)).doubleValue());
		return spTemp;
	}
}
